//
//  YueDanDetailTableViewCell.m
//  CapriceMusic
//
//  Created by 蒋恩浩 on 16/1/11.
//  Copyright © 2016年 MYX. All rights reserved.
//

#import "YueDanDetailTableViewCell.h"

@interface YueDanDetailTableViewCell ()

@property (nonatomic, strong) JEHLabel *titleLabel;
@property (nonatomic, strong) JEHLabel *nickNameLabel;
@property (nonatomic, strong) JEHLabel *updateTimeLabel;
@property (nonatomic, strong) JEHLabel *descriptionLabel;

@end

@implementation YueDanDetailTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.backgroundColor = [UIColor clearColor];
        self.titleLabel = [[JEHLabel alloc] initWithFrame:CGRectZero withFont:16 withTextColor:[UIColor whiteColor]];
        self.nickNameLabel = [[JEHLabel alloc] initWithFrame:CGRectZero withFont:12 withTextColor:[UIColor colorWithRed:30 / 255.0 green:195 / 255.0 blue:153 / 255.0 alpha:1.0]];
        self.updateTimeLabel = [[JEHLabel alloc] initWithFrame:CGRectZero withFont:12 withTextColor:[UIColor grayColor]];
        self.descriptionLabel = [[JEHLabel alloc] initWithFrame:CGRectZero withFont:14 withTextColor:[UIColor whiteColor]];
        self.descriptionLabel.numberOfLines = 0;
        [self addSubview:self.titleLabel];
        [self addSubview:self.updateTimeLabel];
        [self addSubview:self.nickNameLabel];
        [self addSubview:self.descriptionLabel];

        for (int i = 0; i < 3; i++) {
            
            JEHLabel *label = [[JEHLabel alloc] initWithFrame:CGRectZero withFont:12 withTextColor:[UIColor whiteColor]];
            label.tag = 100 + i;
            [self addSubview:label];
        }
    }
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    self.titleLabel.frame = CGRectMake(20, 10, self.width - 40, 30);
    self.nickNameLabel.frame = CGRectMake(20, 40, [self.nickNameLabel getWidthWithFont:12], 20);
    self.updateTimeLabel.frame = CGRectMake(self.width - [self.updateTimeLabel getWidthWithFont:12] - 20, 40, [self.updateTimeLabel getWidthWithFont:12], 20);
    self.descriptionLabel.frame = CGRectMake(20, 80, self.width - 40, self.height - 80);
    for (int i = 0; i < 3; i++) {
        
        JEHLabel *label = (JEHLabel *)[self viewWithTag:100 + i];
        NSInteger with = (self.width - 40) / 3;
        label.frame = CGRectMake(20 + with * i, 60, with, 20);
        if (label.text.length > 0) {
            
            NSString *attributedText = [label.text substringToIndex:5];
            [label attributedText:attributedText withFont:12 withColor:[UIColor grayColor]];
        }
    }
    [self.nickNameLabel attributedText:@"作者:" withFont:12 withColor:[UIColor grayColor]];
}

- (void)setDetailModel:(DetailModel *)detailModel {
    
    if (_detailModel != detailModel) {
        
        _detailModel = detailModel;
    }
    self.titleLabel.text = detailModel.title;
    self.nickNameLabel.text = [NSString stringWithFormat:@"作者: %@", detailModel.yueDanDescribeModel.nickName];
    self.updateTimeLabel.text = [NSString stringWithFormat:@"更新时间: %@", detailModel.updateTime];
    JEHLabel *playCount = (JEHLabel *)[self viewWithTag:100];
    playCount.text = [NSString stringWithFormat:@"播放次数: %d", detailModel.totalViews.intValue];
    JEHLabel *collection = (JEHLabel *)[self viewWithTag:101];
    collection.text = [NSString stringWithFormat:@"收藏数: %d", detailModel.totalFavorites.intValue];
    JEHLabel *integral = (JEHLabel *)[self viewWithTag:102];
    integral.text = [NSString stringWithFormat:@"获得积分: %d", detailModel.integral.intValue];
    self.descriptionLabel.text = detailModel.descriptions;
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
